package com.xhwl.logistics.strategy.impl;

import com.google.common.base.Strings;
import com.xhwl.logistics.bo.VehicleFindCarBO;
import com.xhwl.logistics.bo.cent.VehicleIntegratedConfigBO;
import com.xhwl.logistics.bo.input.QueryVehicleFindCarBO;
import com.xhwl.logistics.converter.mapstruct.VehicleFindCarConverter;
import com.xhwl.logistics.dto.http.CarLocationKeTopDTO;
import com.xhwl.logistics.dto.http.CarRouteKeTopDTO;
import com.xhwl.logistics.dto.http.query.QueryCarLocationKeTopDTO;
import com.xhwl.logistics.dto.http.query.QueryCarRouteKeTopDTO;
import com.xhwl.logistics.service.impl.http.KeTopHttpServiceImpl;
import com.xhwl.logistics.strategy.IVehicleParkingLotFindCarHandler;
import org.springframework.beans.factory.annotation.Autowired;

//@Service
public class VehicleParkingLotKeTopFindCarHandlerImpl implements IVehicleParkingLotFindCarHandler {

    @Autowired
    private KeTopHttpServiceImpl keTopHttpService;

    @Autowired
    private VehicleFindCarConverter vehicleFindCarConverter;

    @Override
    public VehicleFindCarBO findCar(VehicleIntegratedConfigBO vehicleIntegratedConfigBO, QueryVehicleFindCarBO queryVehicleFindCarBO) {
        QueryCarLocationKeTopDTO queryCarLocationKeTopDTO = vehicleFindCarConverter.queryVehicleFindCarBO2QueryCarLocationKeTopDTO(queryVehicleFindCarBO);
        CarLocationKeTopDTO carLocationKeTopDTO = keTopHttpService.queryCarLocation(vehicleIntegratedConfigBO, queryCarLocationKeTopDTO);

        if (Strings.isNullOrEmpty(queryVehicleFindCarBO.getCarportNumber())) {
            return vehicleFindCarConverter.carLocationKeTopDTO2VehicleFindCarBO(carLocationKeTopDTO);
        } else {
            QueryCarRouteKeTopDTO queryCarRouteKeTopDTO = vehicleFindCarConverter.toQueryCarRouteKeTopDTO(queryVehicleFindCarBO, carLocationKeTopDTO);
            CarRouteKeTopDTO carRouteKeTopDTO = keTopHttpService.queryCarRoute(vehicleIntegratedConfigBO, queryCarRouteKeTopDTO);

            return vehicleFindCarConverter.toVehicleFindCarBO(carLocationKeTopDTO, carRouteKeTopDTO);
        }
    }

}
